﻿using ServerGame.GameObject;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static UtilPublic.Redis.ServerRedis;
using static ServerBase.DataBaseRedis.RdsTxt;
using static ServerBase.Config.Conf;
using static ServerPublic.Data.PubDataMethodMgr;
using UtilPublic.ServerLoger;
using UtilLib;
using ServerBase.Protocol;
using static UtilPublic.Serialization.Jsh;
using ServerBase.Service;
using ServerBase.DataBaseRedis;
using ServerBase.Config;

namespace ServerGame.Data
{
    //Key
    public enum EDataGameKey
    {
        Demo,
    }

    /// <summary>
    /// 全局数据
    /// </summary>
    public static partial class DataGame
    {
        public static Dictionary<EDataGameKey, string> DictDataGameDefault = new Dictionary<EDataGameKey, string>()
        {
            { EDataGameKey.Demo,"示例" },
        };

        public static string GameDemo = "";

        public static void GlobalLoadAll()
        {
            #region 玩家ID最小
            //玩家ID最小 121101
            long puidmin = 0;
            if (BaseServerInfo.ServerRunMode == EServerRunMode.正式发布)
            {
                puidmin = 121101;
            }
            var puidold = RedisGame.IdsIncrementGet(RdsIdPuid);
            if (puidold < puidmin)
            {
                RedisGame.IdsIncrementSet(RdsIdPuid, puidmin);
            }
            #endregion

            DataGameGet(EDataGameKey.Demo, out GameDemo);
        }
        public static void GlobalSaveAll()
        {
            DataGameSet(EDataGameKey.Demo, GameDemo);
        }


        #region 方法 Get Set
        public static void DataGameSet<T>(EDataGameKey key, T t)
        {
            ZHashSet(RdsDataGame, key.ToString(), t.ToString());
        }
        public static string DataGameGet(EDataGameKey key)
        {
            var result = ZHashGet(RdsDataGame, key.ToString());
            if (result.IsNullOrEmpty())
            {
                if (DictDataGameDefault.TryGetValue(key, out var dft))
                {
                    result = dft;
                }
            }
            return result;
        }
        public static void DataGameGet(EDataGameKey key, out string value)
        {
            var result = DataGameGet(key);
            value = result;
        }
        public static void DataGameGet(EDataGameKey key, out int value)
        {
            var result = DataGameGet(key);
            value = result.ToInt();
        }
        #endregion


    }




}
